home *** CD-ROM | disk | FTP | other *** search
- // QDDemo.c
- // Copyright 1985, 1987 Consulair Corporation. All rights reserved.
- /* This program creates a picture without drawing it on the screen, writes
- it out to the file 'PicResFile' as a resource of type 'PICT', and then
- reads it in and displays it using DrawPicture. The logic for reading
- and displaying the picture can be used for displaying any 'PICT' resource
- including those created by MacPaint. Finally, it does a copybits just
- as an example of the call
- */
-
- #Options Z
-
- #include <stdio.h>
- #include <QuickDraw.h>
- #include <Window.h>
- #include <Resource.h>
- #include <Font.h>
-
- #define true 1
- #define false 0
-
- Rect picFrame = {20, 20, 220, 220}; //top,left,bottom,right
- Rect ovalRect = {20, 20, 170, 170};
- Rect destRect = {20, 270, 220, 470};
- Rect demoRect = {50, 30, 320, 490};
-
- main()
- {
- Handle tempH;
- PicHandle ph;
- Rect sourceRect;
- WindowPtr demoWindow;
- short x, y, x1, y1;
- short resFile;
- short savedFont, savedFace, savedSize;
-
- // Create a picture and store it into a resource file
-
- demoWindow = NewWindow(0, &demoRect, "\pQuickDraw Demo",
- true, 0, -1, false, 0);
- x = picFrame.left+2;
- y = picFrame.top+2;
- x1 = picFrame.right-54;
- y1 = picFrame.bottom-54;
- savedFont = monaco;
- savedFace = normalStyle;
- savedSize = 9;
- SetPort(demoWindow);
- SetRectRgn(demoWindow->clipRgn,0,0,512,342);
-
- PenNormal();
- PenSize(2,2);
- ph = OpenPicture(&picFrame);
- while ((x1 - x - 4) > 0)
- {
- MoveTo(x, (y+y1)/2);
- LineTo((x+x1)/2, y);
- LineTo(x1, (y+y1)/2);
- LineTo((x+x1)/2, y1);
- LineTo(x, (y+y1)/2);
- x +=4;
- x1 -=4;
- y +=4;
- y1 -=4;
- }
-
- x = picFrame.left;
- y = picFrame.top;
- x1 = picFrame.right-50;
- y1 = picFrame.bottom-50;
-
- TextFont(systemFont);
- TextFace(boldStyle);
- TextSize(12);
- MoveTo(picFrame.right-80,picFrame.bottom-40);
- DrawString("\pDiamond");
- FrameOval(&ovalRect);
- SetRect(&ovalRect, x1-36, y1-8, x1+40, y1+20); //left,top,right,bottom
- FrameRoundRect(&ovalRect,15,15);
- ClosePicture();
-
- demoWindow->txFont = savedFont;
- demoWindow->txFace = savedFace;
- demoWindow->txSize = savedSize;
-
- // Now Write out to resource file
-
- CreateResFile("\pPicResFile"); // create it if not already there
- resFile = OpenResFile("\pPicResFile");
-
- if (tempH = GetNamedResource('PICT', "\pPictDemo"))
- { // remove old copy
- RmveResource(tempH);
- DisposHandle(tempH);
- }
-
- AddResource(ph, 'PICT', UniqueID('PICT'), "\pPictDemo");
- CloseResFile(resFile);
- KillPicture(ph);
-
- // Now open the Resource file, and read the picture into picFrame
-
- resFile = OpenResFile("\pPicResFile");
- if (ph = (PicHandle)GetNamedResource('PICT', "\pPictDemo"))
- DrawPicture(ph, &(*ph)->picFrame);
-
- sourceRect = (*ph)->picFrame;
- // Compensate for QD bug in CopyBits by adding 1 bit to rectangle
- InsetRect(&sourceRect,-1,-1);
- destRect = sourceRect;
- OffsetRect(&destRect,220,0);
-
- // Throw in an example of CopyBits
- CopyBits(&demoWindow->portBits, // srcBits
- &demoWindow->portBits, // dstBits
- &sourceRect, // srcRect
- &destRect, // dstRect
- srcCopy, // mode
- 0); // no mask region
-
- CloseResFile(resFile);
-
- MoveTo(20,240);
- DrawString("\pClick the mouse button to exit");
- while (!Button());
- }
-
-
-
-